cmake_minimum_required(VERSION 2.6)
set(CMAKE_BUILD_TYPE ${KONOHA_BUILD_TYPE})

project(compiler)
set(PACKAGE_SOURCE_CODE compiler.c)
set(PACKAGE_SCRIPT_CODE compiler.k)

set(PACKAGE_NAME    ${PROJECT_NAME})
set(PACKAGE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(PACKAGE_STRING  ${CMAKE_PROJECT_NAME}-${PACKAGE_VERSION})
set(KONOHA_PACKAGE_DIR konoha/package/${KONOHA_VERSION}/konoha.${PROJECT_NAME})

set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
		${CMAKE_CURRENT_SOURCE_DIR}/include  ${CMAKE_CURRENT_BINARY_DIR}
		${KONOHA_INCLUDE_DIRS})
include_directories(${INCLUDE_DIRS})

add_definitions(-D_SETUP)


add_library(${PACKAGE_NAME} SHARED ${PACKAGE_SOURCE_CODE})
set_target_properties(${PACKAGE_NAME} PROPERTIES PREFIX "")
target_link_libraries(${PACKAGE_NAME} konoha ${PACKAGE_EXTRA_LIBRARY})

add_executable(konohac "konohac.c")
target_link_libraries(konohac konoha)
install(TARGETS konohac RUNTIME DESTINATION bin)

install(TARGETS ${PACKAGE_NAME} DESTINATION ${KONOHA_PACKAGE_DIR})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGE_SCRIPT_CODE} DESTINATION ${KONOHA_PACKAGE_DIR})


enable_testing()
set(k ${CMAKE_INSTALL_PREFIX}/bin/konohac)
set(opt "--emit-llvm" "--run")
set(DIR "${CMAKE_CURRENT_SOURCE_DIR}/llvm_test")
add_test(NAME "cast.k"    COMMAND ${k} ${opt} "${DIR}/cast.k")
add_test(NAME "ctro.k"    COMMAND ${k} ${opt} "${DIR}/ctor.k")
add_test(NAME "do.k"      COMMAND ${k} ${opt} "${DIR}/do.k")
add_test(NAME "fib.k"     COMMAND ${k} ${opt} "${DIR}/fib.k")
add_test(NAME "for.k"     COMMAND ${k} ${opt} "${DIR}/for.k")
add_test(NAME "fornest.k" COMMAND ${k} ${opt} "${DIR}/fornest.k")
add_test(NAME "gc.k"      COMMAND ${k} ${opt} "${DIR}/gc.k")
add_test(NAME "global.k"  COMMAND ${k} ${opt} "${DIR}/global.k")
add_test(NAME "hello.k"   COMMAND ${k} ${opt} "${DIR}/hello.k")
add_test(NAME "if.k"      COMMAND ${k} ${opt} "${DIR}/if.k")
add_test(NAME "new.k"     COMMAND ${k} ${opt} "${DIR}/new.k")
add_test(NAME "print.k"   COMMAND ${k} ${opt} "${DIR}/print.k")
add_test(NAME "test.k"    COMMAND ${k} ${opt} "${DIR}/test.k")
add_test(NAME "while.k"   COMMAND ${k} ${opt} "${DIR}/while.k")
add_test(NAME "and.k"     COMMAND ${k} ${opt} "${DIR}/and.k")
add_test(NAME "dynamic.k" COMMAND ${k} ${opt} "${DIR}/dynamic.k")
add_test(NAME "micro.k"   COMMAND ${k} ${opt} "${DIR}/microbench3.k")
add_test(NAME "downcast.k" COMMAND ${k} ${opt} "${DIR}/downcast.k")
add_test(NAME "int_op.k"   COMMAND ${k} ${opt} "${DIR}/int_op.k")
add_test(NAME "float_op.k" COMMAND ${k} ${opt} "${DIR}/float_op.k")
add_test(NAME "virtual.k"  COMMAND ${k} ${opt} "${DIR}/virtual.k")
add_test(NAME "iterator.k" COMMAND ${k} ${opt} "${DIR}/iterator.k")
add_test(NAME "switch.k"   COMMAND ${k} ${opt} "${DIR}/switch.k")

add_test(NAME "fannkuch"     COMMAND ${k} ${opt} "${DIR}/shootout-fannkuch.k")
add_test(NAME "fasta"        COMMAND ${k} ${opt} "${DIR}/shootout-fasta.k")
add_test(NAME "fastaredux"   COMMAND ${k} ${opt} "${DIR}/shootout-fastaredux.k")
add_test(NAME "mandelbrot"   COMMAND ${k} ${opt} "${DIR}/shootout-mandelbrot.k")
add_test(NAME "nbody"        COMMAND ${k} ${opt} "${DIR}/shootout-nbody.k")
add_test(NAME "nsieve"       COMMAND ${k} ${opt} "${DIR}/shootout-nsieve.k")
add_test(NAME "partialsums"  COMMAND ${k} ${opt} "${DIR}/shootout-partialsums.k")
add_test(NAME "spectralnorm" COMMAND ${k} ${opt} "${DIR}/shootout-spectralnorm.k")

add_test(NAME "app-ao.k"            COMMAND ${k} ${opt} "${DIR}/app-ao.k")
add_test(NAME "app-FFT.k"           COMMAND ${k} ${opt} "${DIR}/app-FFT.k")
add_test(NAME "app-MonteCarlo.k"    COMMAND ${k} ${opt} "${DIR}/app-MonteCarlo.k")
add_test(NAME "app-SparseCompRow.k" COMMAND ${k} ${opt} "${DIR}/app-SparseCompRow.k")
add_test(NAME "app-deltablue.k"     COMMAND ${k} ${opt} "${DIR}/app-deltablue.k")
add_test(NAME "app-dhrystone.k"     COMMAND ${k} ${opt} "${DIR}/app-dhrystone.k")
add_test(NAME "app-linpack.k"       COMMAND ${k} ${opt} "${DIR}/app-linpack.k")
add_test(NAME "app-richards.k"      COMMAND ${k} ${opt} "${DIR}/app-richards.k")
add_test(NAME "app-tarai.k"         COMMAND ${k} ${opt} "${DIR}/app-tarai.k")
add_test(NAME "gc-linklist.k"       COMMAND ${k} ${opt} "${DIR}/gc-linklist.k")
add_test(NAME "gc-tree.k"           COMMAND ${k} ${opt} "${DIR}/gc-tree.k")

add_test(NAME "t-array.k"  COMMAND ${k} ${opt} "${DIR}/t-array.k")
add_test(NAME "t-bool.k"   COMMAND ${k} ${opt} "${DIR}/t-bool.k")
add_test(NAME "t-fib.k"    COMMAND ${k} ${opt} "${DIR}/t-fib.k")
add_test(NAME "t-map.k"    COMMAND ${k} ${opt} "${DIR}/t-map.k")
add_test(NAME "t-math.k"   COMMAND ${k} ${opt} "${DIR}/t-math.k")
add_test(NAME "t-string.k" COMMAND ${k} ${opt} "${DIR}/t-string.k")

add_test(NAME "vm-assign"         COMMAND ${k} ${opt} "${DIR}/vm-assign.k"        )
add_test(NAME "vm-eval"           COMMAND ${k} ${opt} "${DIR}/vm-eval.k"          )
add_test(NAME "vm-fib"            COMMAND ${k} ${opt} "${DIR}/vm-fib.k"           )
add_test(NAME "vm-field"          COMMAND ${k} ${opt} "${DIR}/vm-field.k"         )
add_test(NAME "vm-global"         COMMAND ${k} ${opt} "${DIR}/vm-global.k"        )
add_test(NAME "vm-inheritance"    COMMAND ${k} ${opt} "${DIR}/vm-inheritance.k"   )
add_test(NAME "vm-io"             COMMAND ${k} ${opt} "${DIR}/vm-io.k"            )
add_test(NAME "vm-loop"           COMMAND ${k} ${opt} "${DIR}/vm-loop.k"          )
add_test(NAME "vm-map"            COMMAND ${k} ${opt} "${DIR}/vm-map.k"           )
add_test(NAME "vm-nestedcall"     COMMAND ${k} ${opt} "${DIR}/vm-nestedcall.k"    )
add_test(NAME "vm-new"            COMMAND ${k} ${opt} "${DIR}/vm-new.k"           )
add_test(NAME "vm-opt"            COMMAND ${k} ${opt} "${DIR}/vm-opt.k"           )
add_test(NAME "vm-pagerank"       COMMAND ${k} ${opt} "${DIR}/vm-pagerank.k"      )
add_test(NAME "vm-qsbench"        COMMAND ${k} ${opt} "${DIR}/vm-qsbench.k"       )
add_test(NAME "vm-string"         COMMAND ${k} ${opt} "${DIR}/vm-string.k"        )
add_test(NAME "vm-toyinterpreter" COMMAND ${k} ${opt} "${DIR}/vm-toyinterpreter.k")

